package com.fumihiko.modules.jxxm.controller;

import java.text.ParseException;
import java.util.*;

import cn.hutool.core.lang.Dict;
import com.fumihiko.modules.sys.entity.SysDictEntity;
import com.fumihiko.modules.sys.service.SysDictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fumihiko.modules.jxxm.entity.RetiredEmployeesEntity;
import com.fumihiko.modules.jxxm.service.RetiredEmployeesService;
import com.fumihiko.common.utils.PageUtils;
import com.fumihiko.common.utils.R;



/**
 *
 *
 * @author hanwenpeng
 * @email devilzwy@gmail.com
 * @date 2021-11-30 18:29:50
 */
@RestController
@RequestMapping("jxxm/retiredemployees")
public class RetiredEmployeesController {
    @Autowired
    private RetiredEmployeesService retiredEmployeesService;

    @Autowired
    private SysDictService sysDictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("jxxm:retiredemployees:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询列表
     */
    @RequestMapping("/searchList")
    @RequiresPermissions("jxxm:retiredemployees:searchList")
    public R searchList(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.searchPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 退休费错误检查列表
     */
    @RequestMapping("/listError")
    @RequiresPermissions("jxxm:retiredemployees:listError")
    public R listError(@RequestParam Map<String, Object> params){
        List<RetiredEmployeesEntity> list =  retiredEmployeesService.queryErrorPage(params);

        return R.ok().put("list", list);
    }

    /**
     * 个人编码重复查询
     */
    @RequestMapping("/listRepeat")
    @RequiresPermissions("jxxm:retiredemployees:listRepeat")
    public R listRepeat(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryRepeatPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 死亡人员列表
     */
    @RequestMapping("/listDeath")
    @RequiresPermissions("jxxm:retiredemployees:listDeath")
    public R listDeath(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryDeathPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询死亡人员列表
     */
    @RequestMapping("/searchListDeath")
    @RequiresPermissions("jxxm:retiredemployees:searchListDeath")
    public R searchListDeath(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.searchDeathPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 删除人员列表
     */
    @RequestMapping("/listDelete")
    @RequiresPermissions("jxxm:retiredemployees:listDelete")
    public R listDelete(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryDeletePage(params);

        return R.ok().put("page", page);
    }

    /**
     * 条件查询删除人员列表
     */
    @RequestMapping("/searchListDelete")
    @RequiresPermissions("jxxm:retiredemployees:searchListDelete")
    public R searchListDelete(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.searchDeletePage(params);

        return R.ok().put("page", page);
    }

    /**
     * 死亡人员导出
     */
    @RequestMapping("/listDeathExcel")
    @RequiresPermissions("jxxm:retiredemployees:listDeathExcel")
    public R listDeathExcel(@RequestParam Map<String, Object> params){
        List<RetiredEmployeesEntity> list = retiredEmployeesService.listDeathExcel(params);

        return R.ok().put("list", list);
    }


    /**
     * 姓名列表
     */
    @RequestMapping("/name/{query}")
    @RequiresPermissions("jxxm:retiredemployees:name")
    public R name(@PathVariable("query") String query){
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getName(query);

        return R.ok().put("list", list);
    }

    /**
     * 统计分析柱状图数据
     */
    @RequestMapping("/select/{type}")
    @RequiresPermissions("jxxm:retiredemployees:select")
    public R select(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getTypeNum(type,area);
        List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Object> ints = new ArrayList<>();
        Map<String, Object> tempMap = new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getYuYue());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getYuYue());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getYuYue());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getYuYue());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getYuYue());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getYuYue());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getYuYue());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getYuYue());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getYuYue());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getYuYue());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getYuYue());
            }

        }
        for (int i = 0; i <listDict.size() ; i++) {
            if(tempMap.containsKey(listDict.get(i).getValue()))
            {
                ints.add(tempMap.get(listDict.get(i).getValue()));
            }
//            else
//            {
//                ints.add(0);
//            }
        }
        return R.ok().put("list", ints);
    }

    /**
     * 统计分析饼状图数据
     */
    @RequestMapping("/pie/{type}")
    @RequiresPermissions("jxxm:retiredemployees:pie")
    public R pie(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getTypeNum(type,area);
        List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Map<String, Object>> listaa = new ArrayList<>();
        Map<String, Object> tempMap = new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getYuYue());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getYuYue());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getYuYue());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getYuYue());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getYuYue());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getYuYue());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getYuYue());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getYuYue());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getYuYue());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getYuYue());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getYuYue());
            }
        }
        for (int i = 0; i <listDict.size() ; i++) {
            Map<String, Object> map11 = new HashMap<>();
            if(tempMap.containsKey(listDict.get(i).getValue()))
            {

                map11.put("name",listDict.get(i).getValue());
                map11.put("value",tempMap.get(listDict.get(i).getValue()));
                listaa.add(map11);
            }
//            else
//            {
//                map11.put("name",listDict.get(i).getValue());
//                map11.put("value",0);
//                listaa.add(map11);
//            }
        }
        return R.ok().put("list", listaa);
    }


    /**
     * 统计分析饼x,y轴数据
     */
    @RequestMapping("/xAxis/{type}")
    @RequiresPermissions("jxxm:retiredemployees:xAxis")
    public R xAxis(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getTypeNum(type,area);
        List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Object> ints = new ArrayList<>();
        Map<String, Object> tempMap = new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getYuYue());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getYuYue());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getYuYue());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getYuYue());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getYuYue());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getYuYue());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getYuYue());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getYuYue());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getYuYue());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getYuYue());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getYuYue());
            }
        }
        for (int i = 0; i <listDict.size() ; i++) {
            if(tempMap.containsKey(listDict.get(i).getValue()))
            {
                ints.add(listDict.get(i).getValue());
            }
        }

        return R.ok().put("list", ints);

    }
    /**
     * 地图点击事件
     */
    @RequestMapping("/map/{contrys}")
    @RequiresPermissions("jxxm:retiredemployees:map")
    public R map(@PathVariable("contrys") String contrys){
        List<Map<String, Object>> listaa = new ArrayList<>();
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getStreetByContry(contrys);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> tempMap = new HashMap<>();
            tempMap.put("name",list.get(i).getStreet());
            tempMap.put("value",list.get(i).getYuYue());
            listaa.add(tempMap);
        }
        return R.ok().put("list", listaa);

    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("jxxm:retiredemployees:info")
    public R info(@PathVariable("id") Long id){
		RetiredEmployeesEntity retiredEmployees = retiredEmployeesService.getById(id);

        return R.ok().put("retiredEmployees", retiredEmployees);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("jxxm:retiredemployees:save")
    public R save(@RequestBody RetiredEmployeesEntity retiredEmployees){
		retiredEmployeesService.save(retiredEmployees);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("jxxm:retiredemployees:update")
    public R update(@RequestBody RetiredEmployeesEntity retiredEmployees){
		retiredEmployeesService.updateById(retiredEmployees);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("jxxm:retiredemployees:delete")
    public R delete(@RequestBody Long[] ids){
		//retiredEmployeesService.removeByIds(Arrays.asList(ids));
        retiredEmployeesService.removeByState(ids);

        return R.ok();
    }

    /**
     * 计算
     */
    @RequestMapping("/getResult")
    @RequiresPermissions("jxxm:retiredemployees:getResult")
    public R getResult() throws ParseException {
        retiredEmployeesService.updateResult();

        return R.ok();
    }

    /**
     * 恢复数据
     */
    @RequestMapping("/recoveryData")
    @RequiresPermissions("jxxm:retiredemployees:recoveryData")
    public R recoveryData(@RequestBody Long[] ids){
        //retiredEmployeesService.removeByIds(Arrays.asList(ids));
        retiredEmployeesService.recoveryById(ids);

        return R.ok();
    }


    /**
     * 2022年养老金病故补发
     */
    @RequestMapping("/listDeathPension")
    @RequiresPermissions("jxxm:retiredemployees:listDeathPension")
    public R listDeathPension(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryDeathPensionPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 2022年养老金病故补发导出
     */
    @RequestMapping("/listDeathPensionExcel")
    @RequiresPermissions("jxxm:retiredemployees:listDeathPensionExcel")
    public R listDeathPensionExcel(@RequestParam Map<String, Object> params){
        List<RetiredEmployeesEntity> list = retiredEmployeesService.listDeathPensionExcel(params);

        return R.ok().put("list", list);
    }

    /**
     * 2022年1月增加养老金
     */
    @RequestMapping("/listAddPension")
    @RequiresPermissions("jxxm:retiredemployees:listAddPension")
    public R listAddPension(@RequestParam Map<String, Object> params){
        PageUtils page = retiredEmployeesService.queryAddPensionPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 2022年1月增加养老金
     */
    @RequestMapping("/listAddPensionAll")
    @RequiresPermissions("jxxm:retiredemployees:listAddPensionAll")
    public R listAddPensionAll(@RequestParam Map<String, Object> params){
        //PageUtils page = retiredEmployeesService.queryAddPensionPage(params);
        List<RetiredEmployeesEntity> list = retiredEmployeesService.getListAddPensionAll();

        return R.ok().put("list", list);
    }

    /**
     * 2022年1月增加养老金导出
     */
    @RequestMapping("/listAddPensionExcel")
    @RequiresPermissions("jxxm:retiredemployees:listAddPensionExcel")
    public R listAddPensionExcel(@RequestParam Map<String, Object> params){
        List<RetiredEmployeesEntity> list = retiredEmployeesService.listAddPensionExcel(params);

        return R.ok().put("list", list);
    }

    /**
     * 调资结束
     */
    @RequestMapping("/isOver")
    @RequiresPermissions("jxxm:retiredemployees:isOver")
    public R isOver(){
        retiredEmployeesService.isOver();

        return R.ok();
    }

    /**
     *  审批表信息
     */
    @RequestMapping("/pension/{id}")
    @RequiresPermissions("jxxm:retiredemployees:pension")
    public R pension(@PathVariable("id") Long id){
        RetiredEmployeesEntity retiredEmployees = retiredEmployeesService.getDataById(id);

        return R.ok().put("retiredEmployees", retiredEmployees);
    }

}
